package com.ayic.garbagerecycle.controller;

import com.ayic.garbagerecycle.pojo.AnalysisRequest;
import com.ayic.garbagerecycle.pojo.Result;
import com.ayic.garbagerecycle.pojo.Station;
import com.ayic.garbagerecycle.pojo.StationInfoLite;
import com.ayic.garbagerecycle.service.AnalysisService;
import com.ayic.garbagerecycle.service.StationService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author AyiC416
 * @ClassName garbagerecycle
 * @date 2025/5/21
 * @Description 分析控制器
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/analysis")
public class AnalysisController {
    // 首先要根据传参决定是对什么进行分析
    //
    @Resource
    private AnalysisService  analysisService;
    @Resource
    private StationService stationService;

    @GetMapping("/queryArea")
    public Result queryArea() {
        List<String> uniqueAreas = stationService.getUniqueAreas();
        return Result.success(uniqueAreas);
    }

    @PostMapping( "/generateReport")
    public Result generateReport(@RequestBody AnalysisRequest analysisRequest) {
        List<String> areaIds = analysisRequest.getAreaIds();
        if (areaIds == null || areaIds.isEmpty()) {
            return Result.error("区域列表不能为空");
        }
        // 暂时返回固定信息以确认参数接收正常

        // 通过工具方法将区域站点分组
        Map<String, List<StationInfoLite>> analysisStations = stationService.getStationsByAreas(areaIds);
//        analysisService.generateReport(analysisStations, areaIds);
        return Result.success(analysisService.generateReport(analysisStations, areaIds),"成功获取区域分析报告");
    }
}
